package ysc.cqnu.operdb.serviceImpl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import ysc.cqnu.operdb.entity.ReceiveUserInfo;
import ysc.cqnu.operdb.entity.ResultData;
import ysc.cqnu.operdb.entity.User;
import ysc.cqnu.operdb.mapper.UserMapper;
import ysc.cqnu.operdb.service.UserRegisteService;

@Component
public class UserRegisteServiceImpl implements UserRegisteService {
    @Autowired
    private User userLogin;
    @Autowired
    private UserMapper userLoginMapper;
    @Autowired
    private ResultData resultData;
    @Override
    public ResultData isRegiste(ReceiveUserInfo receiveLogin) {
        userLogin = userLoginMapper.findByName(receiveLogin.getName());
        if (userLogin!=null){
            resultData.data=null;
            resultData.flag="haveName";
            return resultData;
        }
        try {
            userLoginMapper.insertByName(receiveLogin);
        }
        catch (Exception e){
            resultData.data=null;
            resultData.flag="ErrorDataBase";
            return resultData;
        }
        resultData.data=null;
        resultData.flag="success";
        return resultData;
    }
}
